package com.ruoyi.resume.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.resume.domain.vo.ProjectToTechVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.resume.mapper.CvProjectExperienceMapper;
import com.ruoyi.resume.domain.CvProjectExperience;
import com.ruoyi.resume.service.ICvProjectExperienceService;

/**
 * 项目经历Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-05-31
 */
@Service
public class CvProjectExperienceServiceImpl implements ICvProjectExperienceService 
{
    @Autowired
    private CvProjectExperienceMapper cvProjectExperienceMapper;

    /**
     * 查询项目经历
     * 
     * @param id 项目经历主键
     * @return 项目经历
     */
    @Override
    public CvProjectExperience selectCvProjectExperienceById(Long id)
    {
        return cvProjectExperienceMapper.selectCvProjectExperienceById(id);
    }

    /**
     * 查询项目经历列表
     * 
     * @param cvProjectExperience 项目经历
     * @return 项目经历
     */
    @Override
    public List<CvProjectExperience> selectCvProjectExperienceList(CvProjectExperience cvProjectExperience)
    {
        return cvProjectExperienceMapper.selectCvProjectExperienceList(cvProjectExperience);
    }

    /**
     * 新增项目经历
     * 
     * @param cvProjectExperience 项目经历
     * @return 结果
     */
    @Override
    public int insertCvProjectExperience(List<CvProjectExperience> cvProjectExperience)
    {
        int r = 0;
        for (CvProjectExperience projectExperience : cvProjectExperience) {
            String projectName = projectExperience.getProjectName();
           CvProjectExperience cvProjectExperience1 = cvProjectExperienceMapper.selectCvProjectExperience(projectName);
           if (cvProjectExperience1 == null){
               projectExperience.setCreateTime(DateUtils.getNowDate());
               cvProjectExperienceMapper.insertCvProjectExperience(projectExperience);
               Long id = projectExperience.getId();
               List<Integer> checkList = projectExperience.getCheckList();
               for (Integer tid : checkList) {
                   ProjectToTechVo projectToTechVo = cvProjectExperienceMapper.selectCvProjectExperienceToTech(id,tid);
                   if(projectToTechVo ==null){
                       cvProjectExperienceMapper.insertCvProjectExperienceToTech(id,tid);
                   }
               }
               r++;
           }


        }
        return r;
    }

    /**
     * 修改项目经历
     * 
     * @param cvProjectExperience 项目经历
     * @return 结果
     */
    @Override
    public int updateCvProjectExperience(CvProjectExperience cvProjectExperience)
    {
        return cvProjectExperienceMapper.updateCvProjectExperience(cvProjectExperience);
    }

    /**
     * 批量删除项目经历
     * 
     * @param ids 需要删除的项目经历主键
     * @return 结果
     */
    @Override
    public int deleteCvProjectExperienceByIds(Long[] ids)
    {
        return cvProjectExperienceMapper.deleteCvProjectExperienceByIds(ids);
    }

    /**
     * 删除项目经历信息
     * 
     * @param id 项目经历主键
     * @return 结果
     */
    @Override
    public int deleteCvProjectExperienceById(Long id)
    {
        return cvProjectExperienceMapper.deleteCvProjectExperienceById(id);
    }

    @Override
    public R getProjectName(String projectName) {
        CvProjectExperience cvProjectExperience1 = cvProjectExperienceMapper.selectCvProjectExperience(projectName);

        return R.ok(cvProjectExperience1);
    }
}
